home *** CD-ROM | disk | FTP | other *** search
/ Young Minds / Young Minds Interactive CD-ROM.ISO / conquest / execute.c < prev    next >
Encoding:
C/C++ Source or Header  |  1987-10-26  |  3.1 KB  |  128 lines

  1. /*conquest is copyrighted 1986 by Ed Barlow.
  2.  *  I spent a long time writing this code & I hope that you respect this.  
  3.  *  I give permission to alter the code, but not to copy or redistribute
  4.  *  it without my explicit permission.  If you alter the code, 
  5.  *  please document changes and send me a copy, so all can have it.  
  6.  *  This code, to the best of my knowledge works well,  but it is my first
  7.  *  'C' program and should be treated as such.  I disclaim any
  8.  *  responsibility for the codes actions (use at your own risk).  I guess
  9.  *  I am saying "Happy gaming", and am trying not to get sued in the process.
  10.  *                                                Ed
  11.  */
  12.  
  13. /*EXECUTE THE PROGRAM*/
  14. #include "header.h"
  15. extern short country;
  16.  
  17. execute()
  18. {
  19.     FILE *fp, *fopen();
  20.     int cmd;
  21.     char comment[20];
  22.     char temp[10];
  23.     int armynum;
  24.     short nation;
  25.     short int x,y;
  26.     int execed=0;
  27.     int done=0;
  28.     char line[80];
  29.  
  30.     /*execute in random order*/
  31.     /*open EXEFILE file*/
  32.     if ((fp=fopen(EXEFILE,"r"))==NULL) {
  33.         printf("\nerror on read \n");
  34.         return(0);
  35.     }
  36.  
  37.     /*read in file*/
  38.     if(fgets(line,80,fp)==NULL) done=1;
  39.     while(done==0) {
  40.         /*read and parse a new line*/
  41.         sscanf(line,"%s %d %hd %d %hd %hd %s",temp,&cmd,&nation,&armynum,&x,&y,comment);
  42.         if(country==nation) {
  43.             execed=1;
  44.             switch(cmd){
  45.             case XASTAT:        /*Aadjstat*/
  46.                 if((x>0)&&(x<6))  ASTAT=x;
  47.                 break;
  48.             case XAMEN:    /*Aadjmen*/
  49.                 ASOLD=x;
  50.                 break;
  51.             case XALOC:    /*Aadjloc*/
  52.                 AXLOC=x;
  53.                 AYLOC=y;
  54.                 break;
  55.             case XNLOC: /*nadjloc*/
  56.                 ntn[country].nvy[armynum].xloc=x;
  57.                 ntn[country].nvy[armynum].yloc=y;
  58.                 break;
  59.             case XNASHP: /*nadjshp*/
  60.                 ntn[country].nvy[armynum].merchant=x;
  61.                 ntn[country].nvy[armynum].warships=y;
  62.                 break;
  63.             case XECNAME:    /*Nadjname*/
  64.                 strcpy(ntn[country].name,comment);
  65.                 break;
  66.             case XECPAS:    /*Nadjpas*/
  67.                 strncpy(ntn[country].passwd,comment,PASSLTH);
  68.                 break;
  69.             case XECMARK:    /*Echgmark*/
  70.                 ntn[country].mark=comment[0];
  71.                 break;
  72.             case XSADES:    /*Sadjdes*/
  73.                 if((sct[x][y].owner==country)||(country==0)) {
  74.                     sct[x][y].designation=comment[0];
  75.                 }
  76.                 if(sct[x][y].designation==DCAPITOL){
  77.                     ntn[country].capx=x;
  78.                     ntn[country].capy=y;
  79.                 }
  80.                 break;
  81.             case XSACIV:    /*Sadjciv*/
  82.                 sct[x][y].people=armynum;
  83.                 break;
  84.             case XSIFORT:    /*Sincfort*/
  85.                 sct[x][y].fortress++;
  86.                 break;
  87.             case XNAGOLD:    /*Nadjgold:*/
  88.                 ntn[country].tgold = armynum;
  89.                 break;
  90.             case XAMOV:
  91.                 AMOVE=x;
  92.                 break;
  93.             case XNMOV:
  94.                 ntn[country].nvy[armynum].smove=x;
  95.                 break;
  96.             case XSAOWN:
  97.                 sct[x][y].owner=country;
  98.                 break;
  99.             case EDADJ:
  100.                 ntn[country].dstatus[armynum]=x;
  101.                 break;
  102.             case XNARGOLD:
  103.                 ntn[country].jewels = armynum;
  104.                 break;
  105.             case XNAIRON:
  106.                 ntn[country].tiron = armynum;
  107.                 break;
  108.             case INCAPLUS:
  109.                 ntn[country].aplus++;
  110.                 break;
  111.             case INCDPLUS:
  112.                 ntn[country].dplus++;
  113.                 break;
  114.             case CHG_MGK:
  115.                 ntn[country].powers*=x;
  116.                 if(ntn[country].powers!=armynum)
  117.                     printf("ERROR ON MAGIC READ");
  118.                 exenewmgk(x);
  119.             }
  120.         }
  121.         if(fgets(line,80,fp)==NULL) done=1;
  122.     }
  123.     fclose(fp);
  124.     /*return 1 if it did something*/
  125.     if(execed==1) return(1);
  126.     else return(0);
  127. }
  128.